package com.mashibing.constrains;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Arrays;
import java.util.List;

public class IdentityCheckValidator implements ConstraintValidator<IdentityCheck,String> {

    List<String> identityList;

    @Override
    public void initialize(IdentityCheck constraintAnnotation) {
        identityList = Arrays.asList(constraintAnnotation.identityElements());
        ConstraintValidator.super.initialize(constraintAnnotation);
    }

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        return null != s && identityList.contains(s);
    }
}
